natural deduction metalanguage, practical foundations
type theory (dependent, intensional, observational type theory, homotopy type theory)
computational trinitarianism =
propositions as types +programs as proofs +relation type theory/category theory
Currying is a process of transforming an operation on two variables into an operation on one variable that returns a function taking the second variable as an argument. The term is used in computer science and the lambda calculus, where it is often technically important to have operations that act on only one variable at a time. But category theory also recognises it as a natural isomorphism in a closed monoidal category, namely the universal property of an exponential object; thus it is also known as taking the exponential transpose.
The inverse operation is, in the straightforward style of computer science, called uncurrying.
Currying is named after Haskell Curry, in accordance with Stigler's law of eponymy, since it was invented by Moses Schönfinkel. (Perhaps Curry helped popularize the application to lambda calculus?)
In set theory, currying transforms a function defined on a product set to a function that takes values in a function set. That is, starting with
we curry to produce
according to the formula
This is simply applying the universal property of the function set .
In dependent type theory, currying transforms a family of elements defined on a dependent pair type to a family of elements that takes values in a dependent function type. That is, starting with
we curry to produce
according to the formula
This is simply applying the universal property of the dependent function type .
Similarly, in lambda calculus, currying is a device which reduces the study of functions in several arguments to functions in one argument. For example, if is a lambda term in which variables and occur freely (so that is effectively a “function” of and ), the lambda calculus syntax favors the currified expression , which denotes the intuitive expression , where one abstracts variables one at a time.
Later it was observed (by Lawvere) that this is just a special case of a more general “curryfication” for cartesian closed categories (such as Cat or a nice category of spaces), where one has a natural bijection of morphisms:
Indeed, cartesian closed categories are models for lambda calculus.
In fact, currying can be done in any (right) closed monoidal category. In that case, currying transforms a morphism whose source is a tensor product to a morphism whose target is an internal hom. That is, starting with
we curry to produce
Currying is invertible and natural in ; that is, is a natural isomorphism (in any closed monoidal category).
By convention, currying is always done on the last variable. This fits in very nicely with a convention that products associate on the left while internal homs associate on the right. More explicitly, if we use (as is common in computer science) ‘’ for the product (even if it is not cartesian) and ‘’ for the internal hom (so that we must use another symbol, say ‘’, for the external hom), then we need no parentheses to generalise currying
to produce
by currying several times in succession, we turn
into
This does not generalise to , which is one way to see that even the untyped lambda calculus actually has two objects, one of which is a terminal object and one of which can play every other role.
In a closed braided monoidal category (such as a closed symmetric monoidal category, and including the cartesian closed categories such as and the models of lambda calculus), we can also ‘curry through the first variable’ or ‘co-curry’ to produce a map
but computer scientists (or even mathematicians who are being very careful) will see this as a composite operation whose first step is composition with the braiding .
In a left closed monoidal category, currying does not exist, but cocurrying does. Perhaps the product should associate on the right in a left closed monoidal category?
For currying in dependent type theory, see
Section 1.2 and 1.4 in Homotopy Type Theory: Univalent Foundations of Mathematics, The Univalent Foundations Project, Institute for Advanced Study, 2013. (web, pdf)
Egbert Rijke, Section 4.6 in Introduction to Homotopy Type Theory, Cambridge Studies in Advanced Mathematics, Cambridge University Press (arXiv:2212.11082)
Last revised on January 7, 2023 at 01:28:24. See the history of this page for a list of all contributions to it.